package com.mango.leet.code.week2.game376;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * 100149. 找出缺失和重复的数字
 * https://leetcode.cn/contest/weekly-contest-376/problems/find-missing-and-repeated-values/
 * @author mango
 * @since 2023/12/17
 */
public class LC100149 {
    public static int[] findMissingAndRepeatedValues(int[][] grid) {
        int[] result = new int[2];
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < grid.length; i++) {
            for (int j = 0; j < grid[i].length; j++) {
                int num = grid[i][j];
                if (map.containsKey(num)) {
                    result[0] = num;
                } else {
                    map.put(num, 1);
                }
            }
        }
        int len = grid.length * grid[0].length;
        for (int i = 1; i <= len; i++) {
            if (!map.containsKey(i)) {
                result[1] = i;
                break;
            }
        }
        return result;
    }
    public static void main(String[] args) {
        int[][] grid = {
                {1, 3},
                {2, 2}
        };
        System.out.println(Arrays.toString(findMissingAndRepeatedValues(grid)));
    }
}
